<script>
	import {
		getUserinfo
	} from './utils/utils.js'
	import {
		getConfig
	} from './request/common-api.js'
	export default {
		onShow: function() {
			this.onInit()
		},

		onHide: function() {
			clearInterval(this.timer)
		},

		data() {
			return {
				timer: null
			}
		},

		mounted() {
			if (process.env.NODE_ENV !== 'development') {
				this.watchDevtools()
			}
		},

		methods: {
			// 初始化
			onInit() {
				let self = this
				this.watchUser()
				this.getPageConfig()
				this.timer = setInterval(() => {
					if (process.env.NODE_ENV !== 'development') {
						this.watchDevtools()
					}
				}, 4000)
				uni.addInterceptor('navigateTo', {
					success(e) {
						self.watchUser()
					}
				})
			},

			// 禁用用户
			watchUser() {
				let user = getUserinfo()
				let disable = [
					17822, 41170, 22063, 28309, 9661, 9230, 9715, 341, 9662, 22945, 351, 2566, 815, 309, 96354,
					9297
				]
				if (user.id) {
					if (disable.includes(user.id)) {
						uni.reLaunch({
							url: '../home/home'
						})
					}
				}
			},

			// 监听Devtools
			watchDevtools() {
				function doCheck(a) {
					if (("" + a / a)["length"] !== 1 || a % 20 === 0) {
						(function() {}
							["constructor"]("debugger")())
					} else {
						(function() {}
							["constructor"]("debugger")())
					}
					doCheck(++a)
				}
				try {
					doCheck(0)
				} catch (err) {}
			},

			// 获取页面配置
			async getPageConfig() {
				try {
					let {
						code,
						message,
						data
					} = await getConfig()
					if (code === 200) {
						let routes = getCurrentPages()
						this.config.isOpenRank = data.isOpenRank === 'Y' ? true : false
						this.config.bazaar_page = data.isOpenMarket === 'Y' ? true : false
						this.config.topup_btn = data.isOpenRecharge === 'Y' ? true : false
						this.config.sale_btn = data.isOpenSell === 'Y' ? true : false
						this.config.withdraw_btn = data.isOpenWithdraw === 'Y' ? true : false
						this.config.isOpenComposite = data.isOpenComposite === 'Y' ? true : false
						if (routes[0] && routes[0].route && routes[0].route === 'pages/bazaar/bazaar' && data
							.isOpenMarket === 'N') {
							uni.reLaunch({
								url: '../home/home',
								animationType: 'pop-in',
								animationDuration: 200
							})
						}
					} else {
						uni.showToast({
							title: message,
							icon: 'error'
						})
					}
				} catch (err) {
					console.log(err)
				}
			}
		}
	}
</script>
<style lang="scss">
	body {
		background-color: #000000;
	}

	/*每个页面公共css */
	view {
		box-sizing: border-box !important;
	}

	@import "uview-ui/index.scss";
</style>
